import Big, { type BigSource, type RoundingMode } from 'big.js'
import { curry } from 'lodash-es'

export type roundSign = (value: BigSource, dp?: number, rm?: RoundingMode) => Big

export const add = curry((a: BigSource, b: BigSource) => {
  a = new Big(a)
  b = new Big(b)
  return b.add(a)
})

export const minus = curry((a: BigSource, b: BigSource) => {
  a = new Big(a)
  b = new Big(b)
  return b.minus(a)
})

export const mul = curry((a: BigSource, b: BigSource) => {
  a = new Big(a)
  b = new Big(b)
  return b.times(a)
})

export const div = curry((a: BigSource, b: BigSource) => {
  a = new Big(a)
  b = new Big(b)
  return b.div(a)
})

export const sqrt = curry((a: BigSource) => {
  a = new Big(a)
  return a.sqrt()
})

export const toFixed = curry((num: number, value: BigSource) => {
  value = new Big(value)
  return value.toFixed(num)
})

export const round: roundSign = (value, dp, rm) => {
  value = new Big(value)
  return value.round(dp, rm)
}
